package com.webchat.ugc.messaegqueue.consumer.rocketmq;

import com.webchat.common.enums.messagequeue.MessageQueueEnum;
import com.webchat.ugc.messaegqueue.service.MallIMessageConsumeService;
import com.webchat.ugc.mongodb.document.MallChatMessage;
import com.webchat.ugc.service.mall.im.MallChatMessageService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 电商客服系统对话消息持久化RocketMQ队列
 *
 */
@Slf4j
@Component
@RocketMQMessageListener(consumerGroup = "mall_im_message_delay_consume",
                         topic = "delay_queue_mall_ai_im_auto_msg",
                         maxReconsumeTimes = 1)
public class MallIMMessageRocketMQDelayConsumer implements RocketMQListener<String> {


    @Autowired
    private MallIMessageConsumeService mallIMessageConsumeService;

    /**
     * 消息持久化
     * @param message
     */
    @Override
    public void onMessage(String message) {
        log.info("Ai Auto Replay ===> consume delay message: {}", message);
        mallIMessageConsumeService.doConsumeDelayQueueMessageForAutoReplay(message);
    }
}